<template>
  <div class="list">
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <div
        v-for="(item, index) in list"
        :key="index"
        :title="item"
        class="song"
      >
        <h3>{{ item.name }}</h3>
        <div class="singers">
          <span v-for="(singer, index) in item.singer" :key="singer.id">
            {{ singer.name }}
            <span v-show="index != item.singer.length - 1">/</span>
          </span>
          <span v-show="item.album">
            <span>·</span><span>{{ item.album.name }}</span>
            <span v-show="item.album.subtitle">
              <span class="memo_sep">·</span>
              <span>{{ item.album.subtitle }}</span>
            </span>
          </span>
        </div>
      </div>
    </van-list>
  </div>
</template>
<script>
export default {
  props: ["singerId"],
  data() {
    return {
      //   song: {
      //     dissname: "", //标题
      //     logo: "", //歌单logo
      //     headurl: "", //歌单制作者头像
      //     nickname: "", //歌单制作者昵称
      //     visitnum: 0, //歌单播放量
      //   },
      //   songlist: [],
      songnum: 0,
      list: [],
      loading: false,
      finished: false,
      page: 1,
    };
  },
  created() {
    this.getListData(this.singerId, 1, 10);
  },
  methods: {
    getListData(id, page, num) {
      this.$request(
        "get",
        "/singer/songs?singermid=" + id + "&page=" + page + "&num=" + num
      ).then((res) => {
        console.log(res);
        //   this.song.dissname = res.data.dissname;
        //   this.song.logo = res.data.logo;
        //   this.song.headurl = res.data.headurl;
        //   this.song.nickname = res.data.nickname;
        //   this.song.visitnum = res.data.visitnum;
        this.list=this.list.concat(res.data.list) ;
        this.songnum = res.data.total;
      });
    },
    onClickLeft() {
      window.history.length > 1 ? this.$router.go(-1) : this.$router.push("/");
    },
    onLoad() {
      this.loading = false;
      setTimeout(() => {
          
          this.getListData(this.singerId,++this.page,10);
          if (this.list.length>=this.songnum){
              this.finished=true;
          }
        // this.list = this.list.concat(this.songlist.splice(0, 10));
        // console.log(this.list);
        //加载状态结束
        //数据全部加载完成
        // if (this.list.length >= this.songnum) {
        // }
      }, 1000);
    },
  },
};
</script>

<style scoped>
.header > img {
  border-radius: 1rem;
  width: 50%;
}
.nick {
  overflow: hidden;
  display: flex; /**弹性布局*/
  justify-content: center; /*弹性布局中的内容水平居中 */
  align-items: center; /**弹性布局中的内容垂直居中*/
  margin-bottom: 1rem;
}
.nick > img {
  height: 2rem;
  border-radius: 50%;
  margin-right: 0.5rem;
}
.nick > span {
  height: 2rem;
  font-size: 0.8rem;
  line-height: 2rem;
}
.song {
  margin-bottom: 1rem;
}
.song > h3 {
  text-align: left;
  font-size: 1rem;
  padding: 0 2rem;
  margin: 0;
}
.singers {
  text-align: left;
  padding: 0 2rem;
}
.singers span {
  font-size: 0.8rem;
  color: gray;
}
.singers > span:nth-last-child(1) > span:nth-child(1),
span.memo_sep {
  margin: 0 0.3rem;
  font-weight: 900;
  color: red;
}
</style>